package com.gitee.cui.basic.create;

import com.gitee.cui.util.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 创建线程的第一种方式，继承Thread类的方式
 * @author cuiqingqiang
 * @version 1.0
 * @date 2021/11/9 8:54
 **/
@Slf4j
public class CreateThread {

    private static final int TURN = 5;

    static int threadNo = 1;

    static class NewThread extends Thread {
        public NewThread() {
            super("Mall-" + threadNo++);
        }

        @Override
        public void run() {
            for (int i = 1; i < TURN; i++) {
                log.info(getName() + ", 轮次：{}", i);
            }
            log.info("{} 运行结束", getName());
        }
    }

    public static void main(String[] args) {
        Thread thread = null;
        for (int i = 0; i < 2; i++) {
            thread = new NewThread();
            thread.start();
        }
        log.info("{} 运行结束", ThreadUtil.getCurThreadName());
    }
}
